package www.openteam.com.model;

import android.support.annotation.NonNull;

import java.util.List;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.UpdateTypeInfo;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/1/23.
 */

public class SplishDownloadModel extends BaseModel {

    private boolean isQuery = false;


    public boolean queryUpdateInfo(@NonNull int vc
            , @NonNull final SplishDownLoadOnListener splishDownLoadOnListener
    ) {

        httpApiService.queryUpdateInfo(vc)
                .compose(new CommonTransformer<UpdateTypeInfo>())
                .subscribe(new CommonSubscriber<UpdateTypeInfo>(OTApplication.getmContext()) {
                               @Override
                               public void onNext(UpdateTypeInfo updateTypeInfo) {
                                   splishDownLoadOnListener.queryUISuccess(updateTypeInfo);
                                   isQuery = true;
                               }

                               @Override
                               protected void onError(ApiException e) {
                                   super.onError(e);
                                   isQuery=false;
                                   splishDownLoadOnListener.queryUIFail(e.getMessage());
                               }
                           }

                );
        return isQuery;

    }


    public interface SplishDownLoadOnListener {

        void queryUISuccess(UpdateTypeInfo updateTypeInfos);

        void queryUIFail(String failMsg);

    }


}
